package com.dragonfly.shutter.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.dragonfly.shutter.beans.Album;
import com.dragonfly.shutter.beans.Message;
import com.dragonfly.shutter.services.AlbumSelectService;

/**
 * 相册选择控制器（上传时用）
 * @author 黄挺
 *
 */
@Controller
@RequestMapping("/albumSelect.html")
public class AlbumSelectController {
	@Autowired
	private AlbumSelectService albumSelectService;
	
	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView onLoad(HttpSession session, HttpServletRequest request){
		Message message = null;
		Integer userID = (Integer) session.getAttribute("userID");
		
		if(userID == null){
			message = new Message("您尚未登录，请先登录", "请登录", "login.html");
			return new ModelAndView("message", "message", message);
		}
		
		
		List<Album> albums = albumSelectService.doService(userID, request.getRequestURL().toString());
		return new ModelAndView("albumSelect", "albums", albums);
	}
}
